package com.zzw.other;

import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class SupplyDataThread implements Runnable {
	protected MySingnal singnal;
	private List<Integer> data;

	public SupplyDataThread(MySingnal singnal, List data) {
		this.singnal = singnal;
		this.data = data;
	}

	@Override
	public void run() {
		Random random = new Random();
		while (true) {
			if (!singnal.isHasDataToProcess()) {
				try {
					System.out.println(Thread.currentThread().getName() + " start!	 singnal: " + singnal.isHasDataToProcess());
					int x = random.nextInt(10);
					int y = random.nextInt(10);
					data.add(x);
					data.add(y);
					singnal.setHasDataToProcess(true);

					TimeUnit.SECONDS.sleep(2);
					System.out.println(Thread.currentThread().getName() + " end!	 singnal: " + singnal.isHasDataToProcess());
				} catch (InterruptedException e) {
					System.out.println(Thread.currentThread().getName() + " is interrupted");
				}
			}
		}
	}

}
